package me.shurufa.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.shurufa.R;
import me.shurufa.holder.BaseViewHolder;
import me.shurufa.widget.colordialog.PromptDialog;
import me.shurufa.widget.likebutton.LikeButton;

/**
 * 作者 : andy
 * 日期 : 16/3/8 14:50
 * 邮箱 : andyxialm@gmail.com
 * 描述 : 书评列表适配器
 */
public class BookCommentSelfAdapter extends RecyclerView.Adapter<BookCommentSelfAdapter.DigestHolder> {
    private Context mContext;
    private List<String> mDatas;

    public BookCommentSelfAdapter(Context context, List<String> datas) {
        mContext = context;
        this.mDatas = datas;
    }

    @Override
    public DigestHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_item_bookdetail_comment_self, parent, false);
        return new DigestHolder(v);
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    @Override
    public void onBindViewHolder(final DigestHolder holder, final int position) {

        initListener(holder, position);
    }

    private void initListener(DigestHolder holder, int position) {
        // 编辑
        holder.btn_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mContext, mContext.getString(R.string.bar_edit), Toast.LENGTH_SHORT).show();
            }
        });

        // 删除
        holder.btn_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDelDialog();
            }
        });

    }

    private void showDelDialog() {
        PromptDialog dlg = new PromptDialog(mContext);
        dlg.setDialogType(PromptDialog.DIALOG_TYPE_WRONG);
        dlg.setPositiveListener(new PromptDialog.OnPositiveListener() {
            @Override
            public void onClick(PromptDialog dialog) {
                dialog.dismiss();
            }
        });
    }

    public class DigestHolder extends BaseViewHolder {
        @Bind(R.id.tv_comment_content)
        TextView tv_comment_content;
        @Bind(R.id.tv_info_user)
        TextView tv_info_user;
        @Bind(R.id.tv_info_time)
        TextView tv_info_time;

        //@Bind(R.id.btn_praise)
        // LikeButton btn_praise;
        @Bind(R.id.tv_praise_num)
        TextView tv_praise_num;
        @Bind(R.id.tv_comment_num)
        TextView tv_comment_num;

        @Bind(R.id.btn_share)
        Button btn_share;
        @Bind(R.id.btn_comment)
        Button btn_comment;

        @Bind(R.id.btn_edit)
        Button btn_edit;
        @Bind(R.id.btn_del)
        Button btn_del;

        public DigestHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

    }

}
